package com.silverbox.waimai.dubboApi.goodscart;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.silverbox.core.annotation.DataSource;
import com.silverbox.core.exception.CoreException;
import com.silverbox.core.exception.CoreException.CoreExceptionCode;
import com.silverbox.core.util.StringUtils;
import com.silverbox.sweeporder.service.shopcart.impl.ShopCartServiceImpl;
import com.silverbox.waimai.entity.GoodsCart;
import com.silverbox.waimai.entity.GoodsCartDetail;
import com.silverbox.waimai.entity.extend.GoodsCartAndDetail;
import com.silverbox.waimai.entity.extend.GoodsCartExtend;
import com.silverbox.waimai.service.goodscart.GoodsCartDetailService;
import com.silverbox.waimai.service.goodscart.GoodsCartService;

@Service
@DataSource(name = DataSource.DATASOURCE_B)
public class GoodsCartServiceApiImpl implements GoodsCartServiceApi {
	private static Logger logger = LoggerFactory.getLogger(GoodsCartServiceApiImpl.class);

	@Autowired
	private GoodsCartService goodsCartService;

	@Autowired
	private GoodsCartDetailService goodsCartDetailService;

	@Override
	public List<GoodsCartAndDetail> getGoodsCartByBuyerId(Integer storeId, String buyerId, String startDate,
			String endDate,Integer clientOrderMode) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (buyerId == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (startDate == null) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (endDate == null) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (clientOrderMode == null) {
			throw new CoreException("clientOrderMode is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCartExtend = new GoodsCartExtend();
		goodsCartExtend.setStoreId(storeId);
		goodsCartExtend.setBuyerId(buyerId);
		goodsCartExtend.setStartDate(startDate);
		goodsCartExtend.setEndDate(endDate);
		if(new Integer(4).equals(clientOrderMode) || new Integer(81).equals(clientOrderMode)){
			goodsCartExtend.setSystemBuyerId("system_"+buyerId);
		}
		return goodsCartService.getGoodsCart(goodsCartExtend);
	}

	@Override
	public List<GoodsCartAndDetail> getGoodsCartByTableNo(Integer storeId, String tableNo, String startDate,
			String endDate,Integer clientOrderMode) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (tableNo == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (startDate == null) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (endDate == null) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCartExtend = new GoodsCartExtend();
		goodsCartExtend.setStoreId(storeId);
		goodsCartExtend.setTableNo(tableNo);
		goodsCartExtend.setStartDate(startDate);
		goodsCartExtend.setEndDate(endDate);
		return goodsCartService.getGoodsCart(goodsCartExtend);
	}
	
	@Override
	public List<GoodsCartAndDetail> getGoodsCartByTableNoAndBuyerId(Integer storeId, String tableNo, String startDate,
			String endDate, String buyerId) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (tableNo == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (startDate == null) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (endDate == null) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (buyerId == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCartExtend = new GoodsCartExtend();
		goodsCartExtend.setStoreId(storeId);
		goodsCartExtend.setTableNo(tableNo);
		goodsCartExtend.setStartDate(startDate);
		goodsCartExtend.setEndDate(endDate);
		goodsCartExtend.setBuyerId(buyerId);
		return goodsCartService.getGoodsCart(goodsCartExtend);
	}

	@Override
	public int saveGoodsCart(GoodsCartAndDetail goodsCartAndDetail) {
		if (goodsCartAndDetail == null) {
			throw new CoreException("goodsCartAndDetail is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		Integer id;
		// 保存购物车
		goodsCartService.addGoodsCart(goodsCartAndDetail);
		id = goodsCartAndDetail.getId();
		// 保存购物车明细
		List<GoodsCartDetail> addlist = goodsCartAndDetail.getDetails();
		if (!CollectionUtils.isEmpty(addlist) && addlist.size() > 0) {
			goodsCartDetailService.addGoodsCartDetail(addlist, id);
		}
		return id;
	}

	@Override
	public int deleteGoodsCartById(Integer id) {
		if (id == null) {
			throw new CoreException("id is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		// 删除购物车
		int num = goodsCartService.deleteGoodsCartById(id);
		// 删除购物车明细
		goodsCartDetailService.deleteGcDetailByGcId(id);
		return num;
	}

	@Override
	public void removeGoodsCartByTableNo(Integer storeId, String tableNo, Integer mustOrder) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (tableNo == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCart goodsCart = new GoodsCart();
		goodsCart.setShopperId(storeId);
		goodsCart.setTableNo(tableNo);
		goodsCart.setMustOrder(mustOrder);
		// 先清空购物车明细（需要根据购物车关联购物车明细）
		goodsCartDetailService.removeGoodsCartDetail(goodsCart);
		// 清空购物车
		goodsCartService.removeGoodsCart(goodsCart);
	}
	
	@Override
	public void removeGoodsCartByTableNoAndBuyerId(Integer storeId, String tableNo, Integer mustOrder, String buyerId) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (tableNo == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (buyerId == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCart goodsCart = new GoodsCart();
		goodsCart.setShopperId(storeId);
		goodsCart.setTableNo(tableNo);
		goodsCart.setBuyerId(buyerId);
		goodsCart.setMustOrder(mustOrder);
		// 先清空购物车明细（需要根据购物车关联购物车明细）
		goodsCartDetailService.removeGoodsCartDetail(goodsCart);
		// 清空购物车
		goodsCartService.removeGoodsCart(goodsCart);
	}

	@Override
	public void removeGoodsCartByBuyerId(Integer storeId, String buyerId ,Integer mustOrder) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (buyerId == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCart goodsCart = new GoodsCart();
		goodsCart.setShopperId(storeId);
		goodsCart.setBuyerId(buyerId);
		goodsCart.setMustOrder(mustOrder);
		// 先清空购物车明细（需要根据购物车关联购物车明细）
		goodsCartDetailService.removeGoodsCartDetail(goodsCart);
		// 清空购物车
		goodsCartService.removeGoodsCart(goodsCart);
	}

	@Override
	public GoodsCart getSamePropGoodsByTableNo(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getStartDate() == null) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getEndDate() == null) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getTableNo() == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.getSameGoodsProp(goodsCart);
	}
	
	@Override
	public int getSameGoodsDiffPropNumByTableNo(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getStartDate() == null) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getEndDate() == null) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getTableNo() == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.getSameGoodsDiffPropNum(goodsCart);
	}

	@Override
	public GoodsCartAndDetail getGoodsCartById(Integer id) {
		return goodsCartService.getGoodsCartById(id);
	}

	@Override
	public int updateGoodsCart(GoodsCart goodsCart) {
		if (goodsCart.getId() == null) {
			throw new CoreException("goodsCart is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getBuyCount() == null) {
			throw new CoreException("buyCount is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.updateGoodsCart(goodsCart);
	}

	@Override
	public int updateGoodsCartPackByTableNo(Integer storeId, String tableNo, String goodsDesc) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (tableNo == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsDesc == null) {
			throw new CoreException("goodsDesc is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCart = new GoodsCartExtend();
		goodsCart.setStoreId(storeId);
		goodsCart.setTableNo(tableNo);
		goodsCart.setGoodsDesc(goodsDesc);
		return goodsCartService.updateGoodsCartForPack(goodsCart);
	}
	
	@Override
	public int updateGoodsCartPackByTableNoAndBuyerId(Integer storeId, String tableNo, String goodsDesc, String buyerId) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (tableNo == null) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsDesc == null) {
			throw new CoreException("goodsDesc is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (buyerId == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCart = new GoodsCartExtend();
		goodsCart.setStoreId(storeId);
		goodsCart.setTableNo(tableNo);
		goodsCart.setBuyerId(buyerId);
		goodsCart.setGoodsDesc(goodsDesc);
		return goodsCartService.updateGoodsCartForPack(goodsCart);
	}

	@Override
	public int updateGoodsCartPackByBuyerId(Integer storeId, String buyerId, String goodsDesc) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (buyerId == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsDesc == null) {
			throw new CoreException("goodsDesc is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCart = new GoodsCartExtend();
		goodsCart.setStoreId(storeId);
		goodsCart.setBuyerId(buyerId);
		goodsCart.setGoodsDesc(goodsDesc);
		return goodsCartService.updateGoodsCartForPack(goodsCart);
	}

	@Override
	public int getGoodsCartPackCountByTableNo(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getBuyerId())) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getTableNo())) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getStartDate())) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getEndDate())) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.getSameGoodsCartPackCount(goodsCart);
	}

	@Override
	public int getGoodsCartPackCountById(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getBuyerId())) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getStartDate())) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getEndDate())) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.getSameGoodsCartPackCount(goodsCart);
	}

	@Override
	public int deleteGoodsPackByTableNo(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getBuyerId())) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getTableNo())) {
			throw new CoreException("tableNo is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getStartDate())) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getEndDate())) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.deleteGoodsCartForPack(goodsCart);
	}

	@Override
	public int deleteGoodsPackByBuyerId(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getBuyerId())) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getStartDate())) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getEndDate())) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.deleteGoodsCartForPack(goodsCart);
	}

	@Override
	public GoodsCart getSamePropGoodsByBuyerId(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getStartDate() == null) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getEndDate() == null) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getBuyerId() == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.getSameGoodsProp(goodsCart);
	}

	@Override
	public int getSameGoodsDiffPropNumByBuyerId(GoodsCartExtend goodsCart) {
		if (goodsCart.getStoreId() == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getGoodsId() == null) {
			throw new CoreException("goodsId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (goodsCart.getSizeId() == null) {
			throw new CoreException("sizeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getStartDate())) {
			throw new CoreException("startDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getEndDate())) {
			throw new CoreException("endDate is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(goodsCart.getBuyerId())) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.getSameGoodsDiffPropNum(goodsCart);
	}

	@Override
	public GoodsCart getGoodsCartByRemarkCommit(GoodsCartExtend goodsCart) {
		return goodsCartService.getGoodsCartByRemarkCommit(goodsCart);
	}

	@Override
	public int updateGoodsCartForTableNo(List<Integer> goodsCartId, String tableName) {
		if (CollectionUtils.isEmpty(goodsCartId)) {
			throw new CoreException("goodsCartId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(tableName)) {
			throw new CoreException("tableName is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		return goodsCartService.updateGoodsCartForTableNo(goodsCartId,tableName);
	}

	@Override
	public int deleteGoodsCartByTableName(Integer storeId, String tableName, String createTime) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(tableName)) {
			throw new CoreException("tableName is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(createTime)) {
			throw new CoreException("createTime is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCart = new GoodsCartExtend();
		goodsCart.setStoreId(storeId);
		goodsCart.setTableNo(tableName);
		goodsCart.setStartDate(createTime);
		return goodsCartService.deleteGoodsCartByTableName(goodsCart);
	}

	@Override
	public int updateGoodsCartForMustGoods(GoodsCartExtend goodsCartExtend, List<GoodsCartAndDetail> goodsCart) {
		return goodsCartService.updateGoodsCartForMustGoods(goodsCartExtend,goodsCart);
	}

	@Override
	public List<GoodsCart> getDeletedNeedGoodsCartByTableNo(Integer storeId, String tableNo, String startDate, String endDate) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(tableNo)) {
			throw new CoreException("tableName is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCartExtend = new GoodsCartExtend();
		goodsCartExtend.setStoreId(storeId);
		goodsCartExtend.setTableNo(tableNo);
		goodsCartExtend.setStartDate(startDate);
		goodsCartExtend.setEndDate(endDate);
		return goodsCartService.getDeletedNeedGoodsCart(goodsCartExtend);
	}

	@Override
	public List<GoodsCart> getDeletedNeedGoodsCartByBuyerId(Integer storeId, String buyerId, String startDate, String endDate) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(buyerId)) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCartExtend = new GoodsCartExtend();
		goodsCartExtend.setStoreId(storeId);
		goodsCartExtend.setBuyerId("system_"+buyerId);
		goodsCartExtend.setStartDate(startDate);
		goodsCartExtend.setEndDate(endDate);
		return goodsCartService.getDeletedNeedGoodsCart(goodsCartExtend);
	}

	@Override
	public int removeDeletedNeedGoodsCartByTableNo(Integer storeId, String tableNo, String startDate, String endDate) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(tableNo)) {
			throw new CoreException("tableName is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCartExtend = new GoodsCartExtend();
		goodsCartExtend.setStoreId(storeId);
		goodsCartExtend.setTableNo(tableNo);
		goodsCartExtend.setStartDate(startDate);
		goodsCartExtend.setEndDate(endDate);
		return goodsCartService.removeDeletedNeedGoodsCart(goodsCartExtend);
	}

	@Override
	public int removeDeletedNeedGoodsCartByBuyerId(Integer storeId, String buyerId, String startDate, String endDate) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (StringUtils.isEmpty(buyerId)) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCartExtend goodsCartExtend = new GoodsCartExtend();
		goodsCartExtend.setStoreId(storeId);
		goodsCartExtend.setBuyerId("system_"+buyerId);
		goodsCartExtend.setStartDate(startDate);
		goodsCartExtend.setEndDate(endDate);
		return goodsCartService.removeDeletedNeedGoodsCart(goodsCartExtend);
	}

	@Override
	public void updateNeedGoodsByTableNo(Integer storeId, String tableName) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (tableName == null) {
			throw new CoreException("tableName is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCart goodsCart = new GoodsCart();
		goodsCart.setShopperId(storeId);
		goodsCart.setTableNo(tableName);
		goodsCartService.updateNeedGoods(goodsCart);
	}

	@Override
	public void updateNeedGoodsByBuyerId(Integer storeId, String buyerId) {
		if (storeId == null) {
			throw new CoreException("storeId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		if (buyerId == null) {
			throw new CoreException("buyerId is null", CoreExceptionCode.EXCP_PARAM_NULL);
		}
		GoodsCart goodsCart = new GoodsCart();
		goodsCart.setShopperId(storeId);
		goodsCart.setBuyerId("system_"+buyerId);
		goodsCartService.updateNeedGoods(goodsCart);
	}
}
